function [veccell,frequencyString]=sample2date(vec,div)
% function veccell=sample2date(vec)
% Takes as imput a calendar vector VEC 
% Assigns a cell vector in which numeric endings are converted to quarters 
% i.e Year.00  becomes Year:Q1 
%     Year.25  becomes Year:Q2 
%     Year.50  becomes Year:Q3 
%     Year.75  becomes Year:Q4
if nargin < 2 %|| isempty(div) 
    div=''; 
end


decimalPart=vec - round(vec);
if any( decimalPart ) ~=0
    disp('Monthly or Quarterly Sample Vector');
    if ~isempty( find( abs(decimalPart - 1/12 ) < 0.001 ) )
        disp('Monthly')
        frequencyString='M'; 
        caseFrequency=3;
        multiple=12; 
        %divisor='M'; 
        %subPeriodCell={'J','F','M','A','M','J','J','A','S','O','N','D'}; 
        subPeriodCell={'M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12'}; 
    else
        disp('Quarterly')
        frequencyString='Q';        
        caseFrequency=2;
        multiple=4; 
        subPeriodCell={'Q1','Q2','Q3','Q4'};
        %divisor='Q'; 
    end
else
    caseFrequency=1;
    frequencyString='A';
end



n=length(vec);
veccell=cell(n,1);
for ii=1:n
    y=fix(vec(ii));
    yc=sprintf('%4.0f',y);   
    if caseFrequency > 1;        
        subPeriod=round(multiple*(vec(ii)-y));
%         if subPeriod > 9
%             qc=strcat(divisor,sprintf('%2.0f',subPeriod+1));
%         else
%             qc=strcat(divisor,sprintf('%1.0f',subPeriod+1));
%         end
        veccell(ii)={[yc,char(subPeriodCell(subPeriod+1))]};
    else
     veccell(ii)={yc};
    end 
end 

